import Request from "@/sdk/pocky-request/index.js";

const order={
	state:{
		orderList:[],		//订单列表
		orderCount:[]		//订单统计
	},
	mutations:{
		//更新店铺列表
		updataList(state,_data){
			state.orderList=_data;
		},
		// 更新订单统计
		updataCount(state,_data){
			state.orderCount=_data;
		}
	},
	actions:{
		// 获取订单统计数据
		getOrderCountBySid(context,_sid){
			return new Promise(resolve=>{
				let r=Request();
				r.request({
					url: '/order/stat.do',
					method: 'post',
					data: {
						storeId: _sid
					}
				}).then(res=>{
					if(res.data.code==1){
						let _all=0,_dfk=0,_tk=0,_tongji=[];
						res.data.data.forEach(x=>{
							if(x.status<10){
								_all=_all+x.ct;
							}
							_tongji[parseInt(x.status)]=x.ct
							if(x.status==1||x.status==2||x.status==3){
								_dfk+=x.ct
							}
							if(x.status==6||x.status==7){
								_tk+=x.ct
							}
						})
						_tongji[0]=_all
						_tongji[10]=_dfk,
						_tongji[11]=_tk,
						context.commit("updataCount",_tongji)
						resolve(res)
					}else{
						// uni.showToast({
						// 	title: '获取订单统计数据失败,'+res.data.msg,
						// 	icon: 'none'
						// });
					}
				})
			})
			
		}
	}
}
export default order